function c = voi_SystemCoords(hfile, vn)
% VOI::SystemCoords  - return BV system coords (128 - TAL)
%
% FORMAT:       bvsc = voi.SystemCoords(vn)
%
% Input fields:
%
%       vn          sub-VOI number
%
% Output fields:
%
%       bvsc        BV System coordinates of requested sub-VOI

% Version:  v0.7g
% Build:    9040105
% Date:     Apr-01 2009, 5:36 AM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'voi') || ...
   ~isa(vn, 'double') || ...
    numel(vn) ~= 1 || ...
    isinf(vn) || ...
    isnan(vn) || ...
    vn < 1 || ...
    vn ~= fix(vn)
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end
bc = bvqxfile_getcont(hfile.L);
if vn > numel(bc.VOI)
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid VOI number.' ...
    );
end

% get coords
c = bc.VOI(vn).Voxels;

% TAL to BV?
if strcmpi(bc.ReferenceSpace, 'tal')
    c = 128 - c;
end
